// 能效分析 模块
import { SystemSpace } from "@/api/interface/efficiency"
import { ResPage } from "@/api/interface/index"
import http from "@/api"

// ------------------峰平谷分析------------------ //
// 峰平谷时段统计-总计
export const peakPlatValleyTotal = (params: SystemSpace.PeakPlatValleyTotalQuery) => {
  return http.post<SystemSpace.PeakPlatValleyTotal[]>("/stat/electric/tou/totalStat", params)
}
// 峰平谷时段统计-耗电量，电费统计
export const peakPlatValleyCostStat = (params: SystemSpace.PeakPlatValleyCostStatQuery) => {
  return http.post<SystemSpace.PeakPlatValleyCostStat>("/stat/electric/tou/costStat", params)
}
// 峰平谷分时统计-电量统计
export const peakPlatValleyDleStat = (params: SystemSpace.PeakPlatValleyDleStatQuery) => {
  return http.post<SystemSpace.PeakPlatValleyDleStat[]>("/stat/electric/tou/eleStat", params)
}
// 峰平谷分时统计-峰平谷占比
export const peakPlatValleyRatioStat = (params: SystemSpace.PeakPlatValleyRatioStatQuery) => {
  return http.post<SystemSpace.PeakPlatValleyRatioStat>("/stat/electric/tou/ratioStat", params)
}
// 分页查询能效数据
export const getLinePageQuery = (params: SystemSpace.LinePageQuery) => {
  return http.post<ResPage<SystemSpace.LinePage>>("/stat/line/page", params)
}
// 导出能效数据
export const exportLineData = (data: any) => {
  const params = { ...data }
  delete params.pageSize
  delete params.pageIndex

  const queryString = Object.keys(params)
    .filter(key => params[key] !== undefined && params[key] !== null && params[key] !== "")
    .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
    .join("&")

  // 使用普通http方法，响应拦截器已处理blob类型
  return http.get<any>(`/stat/line/export?${queryString}`, {
    responseType: "blob"
  })
}
